package com.xywy.tangandroid.logic;


import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.google.gson.Gson;
import com.xywy.tangandroid.bean.BaseHttpResponse;
import com.xywy.tangandroid.bean.User;
import com.xywy.tangandroid.util.JsonUtil;
import com.xywy.tangandroid.util.LogUtil;


public class HttpApi extends Thread {
	private Task $t;
	private Handler $handler;
	private Context $cnt;
	private String resultData;
	private int taskId;
	public static  int CASE = 0;
	
	protected Gson mGson;
	

	public HttpApi(Context _cnt, android.os.Handler _handler, Task _t) {
		$cnt = _cnt;
		$handler = _handler;
		$t = _t;
		
		
	}

	@Override
	public void run() {
		networkExchange();
		
	}

	private void networkExchange() {
		Message mg = Message.obtain();
		taskId = $t.getTaskID();
		mg.what = taskId;
		mg.arg1 = CASE;
		switch (taskId) {
		case Task.REGISTER_COMMIT_USERINFO:
			String commit_user_info_response= XyWyApi.ResgisterUserInfo($cnt,$t.getTaskParams());
			LogUtil.i("REGISTER_COMMIT_USERINFO", "commit_user_info_response"+commit_user_info_response);
			BaseHttpResponse result=JsonUtil.parseJsonToBean(commit_user_info_response, BaseHttpResponse.class);
			
			mg.obj = result;
			break;
			
			
		case Task.REGISTER_VALIDATION://ע���Ϣ��֤
			 String  regirst_phone_code=XyWyApi.ResgisterPhoneConfirm();
			 LogUtil.i("REGISTER_VALIDATION", "regirst_phone_code"+regirst_phone_code);
			 BaseHttpResponse result2=JsonUtil.parseJsonToBean(regirst_phone_code, BaseHttpResponse.class);
		    mg.obj = result2;
			break;
		case Task.LOGIN:
			String login_response= XyWyApi.login($cnt,$t.getTaskParams());
			LogUtil.i("LOGIN", "login_response"+login_response);
			User result1=JsonUtil.parseJsonToBean(login_response, User.class);
			mg.obj = result1;
			break;

		}
		mg.what = taskId;
		mg.arg1 = CASE;
		$handler.sendMessage(mg);
	}

	

}
